def knapsack_greedy(W, weights, values, N):
    # 按价值密度（value/weight）从高到低排序
    items = sorted(zip(weights, values), key=lambda x: x[1]/x[0], reverse=True)
    total_weight = 0
    total_value = 0
    selected = []
    
    for w, v in items:
        if total_weight + w <= W:
            total_weight += w
            total_value += v
            selected.append((w, v))
    
    return total_value, selected

# 示例
W = 10
weights = [2, 3, 4, 5]
values = [3, 4, 5, 6]
N = len(weights)
max_val, items = knapsack_greedy(W, weights, values, N)
print("最大价值（贪心）:", max_val)  # 可能不是最优解（如 4 + 5 = 9 < 10）
print("选择的物品:", items)